#######################################################################################################################
# Script Name: Orchards_Detection.ipynb
# Purpose: To complete the entire object detection workflow in one script
# Modifications to code and comments by: Shannon England
#
# Note: the original script was obtained from the arcgis-python-api-master folder,downloaded from the website
# https://github.com/Esri/arcgis-python-api
#######################################################################################################################
mosaic = r'E:\ShannonE\GDA_Project_SE\Historical_Orthomosaic\Rotated_Mosaic.tif'
mosaic
training_data = r'E:\ShannonE\GDA_Project_SE\Historical_Orthomosaic\Attempt7'
training_data
# importing prepare data library from arcgis to apply transformations and enhance the orchards layer
from arcgis.learn import prepare_data
data = prepare_data(training_data, {1: 'Young Orchard',
2: 'Mixed Orchard',
4: 'Overexposed'})
data.show_batch()
# importing the object detection model that will be used
from arcgis.learn import SingleShotDetector
# settings for single shot detector
ssd = SingleShotDetector(data, grids=[3,2,1])
# finding the optimum learning rate - low learning rate leads to slow training of model
ssd.lr_find()
# showing the model learning the task by showing the loss and validation for the training data
ssd.fit(10, slice(0.001, 0.02))
# visualizing the results of the trained model
ssd.show_results(rows=20, thresh=0.1)
# saving the trained model
ssd.save('OrchardDetector7_2')